﻿namespace OP10.ViewModels
{
    public class ST03CCDManagerViewModel : BindableBase
    {
        private readonly IRegionManager _regionManager;

        public ST03CCDManagerViewModel(IRegionManager regionManager)
        {
            _regionManager = regionManager;
            //开启定时器任务
            DispatcherTimer dispatcherTimer = new DispatcherTimer();
            dispatcherTimer.Interval = TimeSpan.FromMilliseconds(200);
            dispatcherTimer.Tick += OnTick;
            dispatcherTimer.Start();
        }

        private void OnTick(object? sender, EventArgs e)
        {
            ST3bWorkDone = CCDPLCToPC_Global.ST3bWorkDone;
            ST3bCheckOk = CCDPLCToPC_Global.ST3bCheckOk;
            ST3bCheckNg = CCDPLCToPC_Global.ST3bCheckNg;
            Target_PosX = CCDPLCToPC_Global.Target_PosX;
            Target_PosYL = CCDPLCToPC_Global.Target_PosYL;
            Target_PosYR = CCDPLCToPC_Global.Target_PosYR;
            ST3GlassWidth = CCDPLCToPC_Global.ST3GlassWidth;
            ST3GlassPointDis = CCDPLCToPC_Global.ST3GlassPointDis;
        }

        #region 事件
        private DelegateCommand _GoBackCommand;

        public DelegateCommand GoBackCommand =>
            _GoBackCommand ?? (_GoBackCommand = new DelegateCommand(ExecuteGoBackCommand));

        void ExecuteGoBackCommand()
        {
            NavigationParameters param = new NavigationParameters();
            param.Add("StationName", "ST03");
            _regionManager.RequestNavigate(PrismManager.MainViewRegionName, AppViews.ST03View, param);
        }


        private DelegateCommand _CCDAutoTriggerDownCmd;
        public DelegateCommand CCDAutoTriggerDownCmd =>
            _CCDAutoTriggerDownCmd ?? (_CCDAutoTriggerDownCmd = new DelegateCommand(ExecuteCCDAutoTriggerDownCmd));

        void ExecuteCCDAutoTriggerDownCmd()
        {
            CCDPCToPLC_Global.ST3bAutoTrigger = true;
        }


        private DelegateCommand _CCDAutoTriggerUpCmd;
        public DelegateCommand CCDAutoTriggerUpCmd =>
            _CCDAutoTriggerUpCmd ?? (_CCDAutoTriggerUpCmd = new DelegateCommand(ExecuteCCDAutoTriggerUpCmd));

        void ExecuteCCDAutoTriggerUpCmd()
        {
            CCDPCToPLC_Global.ST3bAutoTrigger = false;

        }



        private DelegateCommand _CCDPinBiCommand;
        public DelegateCommand CCDPinBiCommand =>
            _CCDPinBiCommand ?? (_CCDPinBiCommand = new DelegateCommand(ExecuteCCDPinBiCommand));

        void ExecuteCCDPinBiCommand()
        {
            CCDPCToPLC_Global.ST3DisableBT = true;
        }


        private DelegateCommand _CCDUnPinBiCommand;
        public DelegateCommand CCDUnPinBiCommand =>
            _CCDUnPinBiCommand ?? (_CCDUnPinBiCommand = new DelegateCommand(ExecuteCCDUnPinBiCommand));

        void ExecuteCCDUnPinBiCommand()
        {
            CCDPCToPLC_Global.ST3DisableBT = false;

        }


        private DelegateCommand _OpenLightCommand;
        public DelegateCommand OpenLightCommand =>
            _OpenLightCommand ?? (_OpenLightCommand = new DelegateCommand(ExecuteOpenLightCommand));

        void ExecuteOpenLightCommand()
        {
            CCDPCToPLC_Global.ST3LightBT = true;

        }

        private DelegateCommand _UnOpenLightCommand;
        public DelegateCommand UnOpenLightCommand =>
            _UnOpenLightCommand ?? (_UnOpenLightCommand = new DelegateCommand(ExecuteUnOpenLightCommand));

        void ExecuteUnOpenLightCommand()
        {
            CCDPCToPLC_Global.ST3LightBT = false;

        }

        private DelegateCommand _CCDCheckDownCmd;
        public DelegateCommand CCDCheckDownCmd =>
            _CCDCheckDownCmd ?? (_CCDCheckDownCmd = new DelegateCommand(ExecuteCCDCheckDownCmd));

        void ExecuteCCDCheckDownCmd()
        {
            CCDPCToPLC_Global.ST3bCheckTrigger = true;
        }


        private DelegateCommand _CCDCheckUpCmd;
        public DelegateCommand CCDCheckUpCmd =>
            _CCDCheckUpCmd ?? (_CCDCheckUpCmd = new DelegateCommand(ExecuteCCDCheckUpCmd));

        void ExecuteCCDCheckUpCmd()
        {
            CCDPCToPLC_Global.ST3bCheckTrigger = false;

        }

        #endregion


        #region 属性


        private bool _ST3bWorkDone;
        public bool ST3bWorkDone
        {
            get { return _ST3bWorkDone; }
            set { SetProperty(ref _ST3bWorkDone, value); }
        }


        private bool _ST3bCheckOk;
        public bool ST3bCheckOk
        {
            get { return _ST3bCheckOk; }
            set { SetProperty(ref _ST3bCheckOk, value); }
        }
        private bool _ST3bCheckNg;
        public bool ST3bCheckNg
        {
            get { return _ST3bCheckNg; }
            set { SetProperty(ref _ST3bCheckNg, value); }
        }


        private float _Target_PosX;
        public float Target_PosX
        {
            get { return _Target_PosX; }
            set { SetProperty(ref _Target_PosX, value); }
        }


        private float _Target_PosYL;
        public float Target_PosYL
        {
            get { return _Target_PosYL; }
            set { SetProperty(ref _Target_PosYL, value); }
        }

        private float _Target_PosYR;
        public float Target_PosYR
        {
            get { return _Target_PosYR; }
            set { SetProperty(ref _Target_PosYR, value); }
        }


        private float _ST3GlassWidth;
        public float ST3GlassWidth
        {
            get { return _ST3GlassWidth; }
            set { SetProperty(ref _ST3GlassWidth, value); }
        }

        private float _ST3GlassPointDis;
        public float ST3GlassPointDis
        {
            get { return _ST3GlassPointDis; }
            set { SetProperty(ref _ST3GlassPointDis, value); }
        }
        #endregion
    }
}
